package edu.mse.camel.client.serverlib.internal;

import java.util.Calendar;
import java.util.Date;

import camel.client.ClientEvent;


// chat
import camel.client.ClientEventChat;
import edu.mse.camel.client.events.peer.ReceiveChatEvent;
import edu.mse.camel.client.events.peer.ReceiveGenericPeerEvent;
import edu.mse.camel.client.events.peer.ReceiveInvitationEvent;
import edu.mse.camel.client.events.peer.SendChatEvent;
import edu.mse.camel.client.events.peer.SendGenericPeerEvent;

// management
import edu.mse.camel.client.events.server.NotifySessionParticipantChange;
import edu.mse.camel.client.events.server.NotifyTeamStatusChange;
import camel.client.ClientEventGenericPeer;
import camel.client.ClientEventInvite;
import camel.client.ClientEventSessionParticipantChange;
import camel.client.ClientEventTeamStatusChange;
import camel.client.SessionTicket;


public class ClientEventConvertor {
	
	public static ClientEvent convertFromSendChatEvent(SendChatEvent event) {
		ClientEventChat chatEvent = new ClientEventChat();
		chatEvent.setChatMsg(event.getContent());
		return chatEvent;
	}
	
	public static ReceiveChatEvent convertToReceiveChatEvent(ClientEventChat event) {
		Calendar now = Calendar.getInstance();
		now.setTimeInMillis(event.getLocalTime());
		ReceiveChatEvent chatEvent = new ReceiveChatEvent(event.getChatMsg(),event.getOriginator(), now.getTime());
		return chatEvent;
	}
	
	
	public static NotifySessionParticipantChange convertToNotifySessionParticipantChangeEvent(SessionTicket ticket, ClientEventSessionParticipantChange event) {
		NotifySessionParticipantChange notifyEvent = new NotifySessionParticipantChange();
		notifyEvent.setInSession(ticket.isInSession());
		return notifyEvent;
	}
	
	public static ReceiveInvitationEvent convertToReceiveInvitationEvent (SessionTicket ticket, ClientEventInvite event) {
		ReceiveInvitationEvent inviteEvent = new ReceiveInvitationEvent();
		inviteEvent.setFacilitator(event.getFacilitator());
		inviteEvent.setSessionId(event.getSessionId());
		inviteEvent.setSessionTitle(event.getSessionTitle());
		inviteEvent.setSessionDesc(event.getSessionDesc());
		return inviteEvent;
	}

	public static NotifyTeamStatusChange convertToNotifyTeamStatusChangeEvent(
			SessionTicket ticket, ClientEventTeamStatusChange recv) {
		NotifyTeamStatusChange notifyEvent = new NotifyTeamStatusChange();
		notifyEvent.setLoggedIn( ticket.isLogInSuccessful());
		return notifyEvent;
	}

	public static ReceiveGenericPeerEvent convertToReceiveGenericPeerEvent(ClientEventGenericPeer event) {

		Calendar now = Calendar.getInstance();
		now.setTimeInMillis(event.getLocalTime());
		
		ReceiveGenericPeerEvent genericEvent = new ReceiveGenericPeerEvent();
		genericEvent.setUserID(event.getOriginator());
		genericEvent.setData(event.getFreeType());
		genericEvent.setDataType(event.getDataType());
		genericEvent.setSpecificEventId(event.getSpecificEventId());
		genericEvent.setOrginalTime(now.getTime());
		
		return genericEvent;
	}

	public static ClientEventGenericPeer convertFromSendGenericPeerEvent(SendGenericPeerEvent event) {
		ClientEventGenericPeer send = new ClientEventGenericPeer();
		send.setDataType(event.getDataType());
		send.setFreeType(event.getData());
		send.setSpecificEventId(event.getSpecificEventId());
		return send;
	}
}
